package com.itheima.manager;


import com.itheima.common.R;
import com.itheima.domain.ResourceCategory;
import com.itheima.service.IResourceCategoryService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class UmsResourceCategoryManager {
    @DubboReference
    IResourceCategoryService resourceCategoryService;


    //查询所有资源分类
    public R<List<ResourceCategory>> findAll() {

        List<ResourceCategory> list=resourceCategoryService.findAll();
        return R.success(list);
    }
    //添加后台资源分类
    public R<String> saveCategory(ResourceCategory resourceCategory) {
        resourceCategoryService.saveCategory(resourceCategory);
        return R.success("添加资源分类成功");
    }

    //根据ID删除后台资源
    public R<String> deleteById(Long id) {
        Boolean bool = resourceCategoryService.deleteById(id);
        if(bool){
            return  R.success("删除资源分类成功");
        }else{
            return R.error(("此资源分类下含有资源"));
        }
    }

    //修改后台资源分类
    public R<String> updateById(ResourceCategory resourceCategory) {
        resourceCategoryService.updateCategory(resourceCategory);
        return R.success("修改成功");

    }
}
